<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="system_public::header"></th:block>
</head>
<body>
	<table id="list"></table>
	<div id="addOrUpdateDialog" style="display:none;">
		<form method="post">
			<input type="hidden" name="id">
			<table class="addform">
				<tr>
					<td class="title" colspan="2"></td>
				</tr>
				<tr>
					<td class="label">参数名</td>
					<td class="input">
						<input type="text" name="name">
					</td>
				</tr>
				<tr>
					<td class="label">参数值</td>
					<td class="input">
						<input type="text" name="value">
					</td>
				</tr>
				<tr>
					<td class="label">描述</td>
					<td class="input">
						<input type="text" name="description">
					</td>
				</tr>
			</table>
		</form>
	</div>
	<th:block th:include="system_public::footer"></th:block>
	<th:block th:include="system_public::jsfile"></th:block>
	<script th:inline="none">
	$(function(){
		var $list = $('#list');
		var $addOrUpdateDialog = $('#addOrUpdateDialog');
		var $addOrUpdateDialog_form = $addOrUpdateDialog.children('form');
		$list.datagrid({
			title : '系统参数管理',
			fit : true,
			singleSelect: true,
			rownumbers: true,
			url : pageurl+'/system/config/index',
			cls : 'list_padding',
			columns : [[{
				field : 'name',
				title : '参数名',
				width : 120
			},{
				field : 'value',
				title : '参数值',
				width : 200
			},{
				field : 'description',
				title : '描述',
				width : 500
			}]],
			toolbar : [{
				text : '刷新列表',
				iconCls : 'icon-reload',
				handler : function() {
					$list.datagrid("reload");
				}
			},'-',{
				text : '增加参数',
				iconCls : 'icon-add',
				handler : function() {
					$addOrUpdateDialog.dialog("open");
					$addOrUpdateDialog_form.find('td.title').text("增加参数");
					$addOrUpdateDialog_form.attr("action", pageurl+"/system/config/add");
				}
			},'-',{
				text : '修改参数',
				iconCls : 'icon-edit',
				handler : function() {
					var row = $list.datagrid("getSelected");
					if(row) {
						$addOrUpdateDialog.dialog("open");
						$addOrUpdateDialog_form.find('td.title').text("修改参数");
						$addOrUpdateDialog_form.attr("action", pageurl+"/system/config/update");
						$addOrUpdateDialog_form.form("load", row);
					} else {
						$.messager.alert('系统提示','请先选择一行','info');
					}
				}
			},'-',{
				text : '删除参数',
				iconCls : 'icon-remove',
				handler : function() {
					var row = $list.datagrid("getSelected");
					if(row) {
						$.messager.confirm('系统提示','您是否要删除'+row.name+'吗?',function(r){
							if(r) {
								$.post(pageurl+'/system/config/delete/'+row.name,function(result){
									if(result.success) {
										$list.datagrid("reload");
										$.messager.alert('系统提示','删除成功','info');
									} else {
										$.messager.alert('系统提示',result.message,'warning');
									}
								},'json');
							}
						});
					} else {
						$.messager.alert('系统提示','请先选择一行','info');
					}
				}
			}]
		});
		$addOrUpdateDialog.show().dialog({
			title : '参数设置',
			iconCls : 'icon-edit',
			modal : true,
			closed : true,
			width : 450,
			height : 300,
			buttons : [{
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					$addOrUpdateDialog_form.submit();
				}
			},{
				text : '返回',
				iconCls : 'icon-back',
				handler : function() {
					$addOrUpdateDialog.dialog("close");
				}
			}],
			onClose : function() {
				$addOrUpdateDialog_form.form("reset");
			}
		});
		$addOrUpdateDialog_form.form({
			success : function(data) {
				var obj = $.parseJSON(data);
				if(obj.success) {
					$addOrUpdateDialog.dialog("close");
					$list.datagrid("reload");
				} else {
					alert(obj.message);
				}
			}
		});
	});
	</script>
</body>
</html>